<?php
	$connection = mysqli_connect("localhost","root","","frederik-adressedatabase");
	if(isset($_REQUEST["postnummer"])){
		$query = "SELECT * FROM postnummer WHERE postnummer = $_REQUEST[postnummer]";
		$result = mysqli_query($connection,$query);
		$record = mysqli_fetch_array($result);
		$by = $record["By"];
	}
	if(isset($_REQUEST["by"])){
		$by = $_REQUEST["by"];
		$query = "UPDATE postnummer SET postnummer.by='$by' WHERE postnummer=$_REQUEST[postnummer]";
		$result = mysqli_query($connection,$query);
	}
?>

<form action="retpostnummer.php">
    <table border="1">
        <tr>
            <th>Postnummer</th><td><?php echo $_REQUEST["postnummer"] ?></td>
       	</tr>
        <tr>
            <th>By</th><td><input type="text" name="by" value="<?php echo $by ?>"/></td>
       	</tr>
        <tr>
            <td><input type="submit" value="Ret" /></td><td><?php if(isset($_REQUEST["by"])){ echo "Rettet."; } ?></td>
      	</tr>
	</table>
    <input type="hidden" name="postnummer" value="<?php echo $_REQUEST['postnummer'] ?>" />
</form>
<a href="postnumre.php">Tilbage til postnumre</a>
